//
//  JBWMainViewController.m
//  JBWDSK
//
//  Created by 崔志伟 on 2018/7/26.
//  Copyright © 2018年 崔志伟. All rights reserved.
//

#import "JBWMainViewController.h"
#import "JBWTabBarView.h"
#import "JBWMainMeViewController.h"
#import "JBWInformationViewController.h"
#import "JBWGiftViewController.h"

@interface JBWMainViewController ()
@property (nonatomic,strong) JBWTabBarView  *tabBarView ;
@property (nonatomic,strong) UIButton  * dismissBtn;
@property (nonatomic,strong) UIWindow  * rightContentView ;


@end

@implementation JBWMainViewController
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    UIView *bgContentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JBW_PERSON_BG_VIEW_WIDTH, JBW_SCREEN_HEIGHT)];
    bgContentView.backgroundColor = [[UIColor blackColor ]colorWithAlphaComponent:0.8];
    [self.view addSubview:bgContentView];
    self.dismissBtn = [[UIButton alloc]initWithFrame:CGRectMake(JBW_PERSON_BG_VIEW_WIDTH, 0, JBW_SCREEN_WIDTH-JBW_PERSON_BG_VIEW_WIDTH, JBW_SCREEN_HEIGHT)];
     self.dismissBtn.backgroundColor = [UIColor clearColor];
    [self.dismissBtn addTarget:self action:@selector(dismissBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.dismissBtn];
    self.tabBarView = [[JBWTabBarView alloc]initWithFrame:CGRectMake(0, 0, JBW_TABBAR_VIEW_WIDTH, JBW_SCREEN_HEIGHT)];
    [bgContentView addSubview:self.tabBarView];

    CGRect windowRect = CGRectMake(60, 0, JBW_PERSON_BG_VIEW_WIDTH-JBW_TABBAR_VIEW_WIDTH, JBW_SCREEN_HEIGHT);
    self.rightContentView = [[UIWindow alloc] initWithFrame:windowRect];
    self.rightContentView.windowLevel = UIWindowLevelNormal;
    [self.rightContentView makeKeyAndVisible];
    [bgContentView addSubview: self.rightContentView ];
    
    __block  __weak JBWMainViewController *weakSelf = self;
    self.tabBarView.selectItemBlock = ^(NSInteger index) {
        UINavigationController * nav = nil;
        if (index ==0) {
            nav = [[UINavigationController  alloc]initWithRootViewController:[JBWInformationViewController new]];
        }else if (index ==1){
   
            nav = [[UINavigationController  alloc]initWithRootViewController:[JBWGiftViewController new]];
        }else if (index ==2){
  
            nav = [[UINavigationController  alloc]initWithRootViewController:[JBWMainMeViewController new]];
        }
        [nav setNavigationBarHidden:YES];
        weakSelf.rightContentView.rootViewController = nav;

    };
    
    if (self.selectItemIndex == 0) {
        self.tabBarView.selectIndex = 2;
    }else if (self.selectItemIndex == 1){
         self.tabBarView.selectIndex = 1;
    }else if (self.selectItemIndex == 2){
//        self.tabBarView.selectIndex = 0;
    }else if (self.selectItemIndex == 3){
        self.tabBarView.selectIndex = 0;
    }
   
}

- (void)dismissBtnAction{
    [self.rightContentView removeFromSuperview];
    self.rightContentView = nil;
    [JBW_KEY_WINDOW makeKeyWindow];
    [self dismissViewControllerAnimated:NO completion:self.dismissBlock];
}

@end
